<?php
/**
 * (commands) 创建fba收支明细报告
 */
namespace App\Console\Commands\SpApi\Report\CreateAndGet;

use App\Crontab\Daily\SpApi\GrabCreateReport;
use App\Models\Amazon\AmazonReportCondition;
use Illuminate\Console\Command;

class LedgerDetailView extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sp-report:ledger-detail-view {accountId=0}';

    /**
     * The console command description.
     * @var string
     */
    protected $description = 'exe func';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $where = [];
        $multi = true;
        $accountId = $this->argument('accountId');
        if($accountId){
            $where['id'] = $accountId;
        }
        if (file_exists('local.txt')) { //测试账号：账号30-NA
            $where['id'] = 31;
        }

        $reportType = 'GET_LEDGER_DETAIL_VIEW_DATA';
        $end_time = AmazonReportCondition::getStartTime($reportType);
        $start_time = date('Y-m-d',strtotime('-3 days',strtotime($end_time)));

        $data = [
            'report_type' => $reportType,
            'data_start_time' => getDateFormat($start_time),
            'data_end_time' => getDateFormat($end_time),
        ];

        GrabCreateReport::grab($data,$where,$multi);
        $this->info('finish!');
    }
}
